package com.example.demo.ImgTest;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.DateTest.util.DateUtil;
import org.apache.commons.lang3.ObjectUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class PicInfo {
    public static void main(String[] args) {
        // 指定图片文件夹路径
        String imageFolderPath = "D:\\upload_files\\yanhai\\assets\\jiankong4_photo_1\\img";
        // 获取文件夹内的所有图片文件，并按名称进行排序
        File folder = new File(imageFolderPath);
        File[] imageFiles = folder.listFiles();
        List<JSONObject> picUrlList = new ArrayList<>();
        if (ObjectUtils.isNotEmpty(imageFiles)) {
            for (File imageFile : imageFiles) {
                JSONObject jsonObject = new JSONObject();
                String name = imageFile.getName();
                String path = imageFile.getPath();
                String lastModified = DateUtil.getDateTime(new Date(imageFile.lastModified()));
                jsonObject.put("url", path);
                jsonObject.put("name", name);
                jsonObject.put("time", lastModified);
                picUrlList.add(jsonObject);
            }
        }
        System.out.println(picUrlList);
    }
}